import 'dart:convert';

/// 健康资讯
class HealthNews {
  String id,
      createDate,
      updateDate,
      infoTitle,
      infoContent,
      source,
      viewCount,
      mainImage,
      whetherAppointed;

  HealthNews({
    this.id,
    this.createDate,
    this.updateDate,
    this.infoTitle,
    this.infoContent,
    this.source,
    this.viewCount,
    this.mainImage,
    this.whetherAppointed,
  });

  factory HealthNews.fromJson(Map<String, dynamic> data) {
    return HealthNews(
      id: data['id'],
      createDate: data['createDate'],
      updateDate: data['updateDate'],
      infoTitle: data['infoTitle'],
      infoContent: data['infoContent'],
      source: data['source'],
      mainImage: data['mainImage'] ?? '',
      viewCount: data['viewCount']?.toString(),
      whetherAppointed: data['whetherAppointed']?.toString(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'createDate': createDate,
      'updateDate': updateDate,
      'infoTitle': infoTitle,
      'infoContent': infoContent,
      'source': source,
      'viewCount': viewCount,
      'mainImage': mainImage,
      'whetherAppointed': whetherAppointed,
    };
  }

  @override
  String toString() {
    return json.encode(toJson());
  }
}
